from dao.nurse import ratings_list_dao

def list_read():
    result = ratings_list_dao.read()

    if result:
        user_first = result
        print(user_first)
        result = {"code": 20000, "err": 0, "message": "查看训练情况成功",
                  "data": {"userinfo": user_first}}
    else:
        result = {"err": 2, "message": "无数据", "data": {}}
    return result

def id_delete(data):
    id = data["id"]
    print(id)
    result = ratings_list_dao.id_delete(id)

    if result:
        user_first = result
        print(user_first)
        result = {"code": 20000, "err": 0, "message": "删除成功",
                  "data": {"userinfo": user_first}}
    else:
        result = {"err": 2, "message": "删除失败", "data": {}}
    return result

def add(data):
    result = ratings_list_dao.add(data)

    if result:
        user_first = result
        print(user_first)
        result = {"code": 20000, "err": 0, "message": "新增成功",
                  "data": {"userinfo": user_first}}
    else:
        result = {"err": 2, "message": "新增失败", "data": {}}
    return result

def update(data):
    id = data.pop('id', None)

    # 去掉创建时间和修改时间的修改,因为数据库是自动新增的
    data.pop('create_time')
    print(f'打印{data}')

    result = ratings_list_dao.update(data, id)

    if result:
        user_first = result
        print(user_first)
        result = {"code": 20000, "err": 0, "message": "修改成功",
                  "data": {"userinfo": user_first}}
    else:
        result = {"err": 2, "message": "修改失败", "data": {}}
    return result
